<div class="form">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'product-form',
        'htmlOptions' => array('class' => 'form-horizontal'), // comment this line to use long form
        'enableAjaxValidation' => false,
    )); ?>

    <?php $this->widget('Xpress.components.InfoBox', array('heading' => '')); ?>
    <?php if (!$model->IsNewRecord) echo $form->hiddenField($model, "id"); ?>
    <div class="control-group">
        <?php echo $form->labelEx($model, 'name', array('class' => 'control-label',)); ?>
        <div class="controls">
            <?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 1500)); ?>
            <?php echo $form->error($model, 'name'); ?>
        </div>
    </div>
    <div class="control-group">
        <?php echo $form->labelEx($model, 'gallery', array('class' => 'control-label',)); ?>
        <div class="controls">
            <!--            --><?php //echo CHtml::image($model->image) ?>
            <?php /*$this->widget('Gallery.components.widgets.GalleryManagerWidget', array(
            'model' => $model,
            'attribute' => 'gallery',
        ));*/?>
        </div>
    </div>
    <div class="control-group">
        <?php echo $form->labelEx($model, 'alias', array('class' => 'control-label',)); ?>
        <div class="controls">
            <?php echo $form->textField($model, 'alias', array('size' => 60, 'maxlength' => 200)); ?>
            <?php echo $form->error($model, 'alias'); ?>
        </div>
    </div>

    <div class="control-group">
        <?php echo $form->labelEx($model, 'details1', array('class' => 'control-label',)); ?>
        <div class="controls">
            <!--            --><?php //echo $form->textArea($model, 'details1'); ?>
            <?php $this->widget('Xpress.extensions.web.widgets.tinymce.ETinyMce', array(
                'model'=>$model,
                'attribute'=>'details1',
                'editorTemplate'=>'simple',
                'useCompression'=>false,
                'useSwitch'=>false,
                'options'=>array(
                    'theme_advanced_buttons1'=>'cut,copy,paste,pastetext,pasteword,|,search,replace,|,undo,redo,|,removeformat,cleanup,|,spellchecker,|,visualaid,visualchars,|,ltr,rtl,|,code,preview,fullscreen'
                ),
                'width'=>'100%',
                'height'=>'500px',
            )); ?>
            <?php echo $form->error($model, 'details1'); ?>
        </div>
    </div>
    <div class="control-group">
        <?php echo $form->labelEx($model, 'details2', array('class' => 'control-label',)); ?>
        <div class="controls">
            <?php echo $form->textArea($model, 'details2'); ?>
            <?php echo $form->error($model, 'details2'); ?>
        </div>
    </div>
    <div class="control-group">
        <?php $catData = $this->getCategoriesForUpdate($model); ?>
        <?php echo CHtml::label('Categories', '', array('class' => 'control-label')) ?>
        <div class="controls">
            <?php echo CHtml::dropDownList('categories[]', $catData['selected'], $catData['data'], array('multiple' => 'multiple','style'=>'height:200px')) ?>
        </div>
    </div>
    <div class="control-group">
        <?php echo $form->labelEx($model, 'status', array('class' => 'control-label',)); ?>
        <div class="controls">
            <?php echo $form->checkBox($model, 'status'); ?>
            <?php echo $form->error($model, 'status'); ?>
        </div>
    </div>
    <div class="control-group">
        <?php echo $form->labelEx($model, 'on_sale', array('class' => 'control-label',)); ?>
        <div class="controls">
            <?php echo $form->checkBox($model, 'on_sale'); ?>
            <?php echo $form->error($model, 'on_sale'); ?>
        </div>
    </div>
    <div class="on_sale-input hide">
        <div class="control-group">
            <?php echo $form->labelEx($model, 'on_sale_start', array('class' => 'control-label',)); ?>
            <div class="controls">
                <!--                --><?php //echo $form->textField($model, 'on_sale_start', array('readonly' => true,'class'=>'date-picker')) ?>
                <?php
                $pattern = 'dd/MM/yyyy';
                $timestamp = strtotime($model->on_sale_start);
                if ($timestamp !== false)
                    $model->on_sale_start = Yii::app()->getDateFormatter()->format($pattern, $timestamp);
                else
                    $model->on_sale_start = '';
                $idStart = 'on_sale_start_' . time();
                $idEnd = 'on_sale_end_' . time();
                $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'id' => $idStart,
                    'model' => $model,
                    'attribute' => 'on_sale_start',
                    // additional javascript options for the date picker plugin
                    'options' => array(
                        'dateFormat' => 'dd/mm/yy',
                        'beforeShow' => 'js:function(input, inst) {
    $(inst.input).datepicker("option", "minDate", new Date());
    var maxDate = $("#' . $idEnd . '").val();
    if (maxDate != "")
        maxDate = $.datepicker.parseDate(\'dd/mm/yy\', maxDate);
    if (maxDate)
        $(inst.input).datepicker("option", "maxDate", maxDate);
}'
                    ),
                    'htmlOptions' => array(
                        'class' => 'date-picker on_sale_start date-input',
                        'readonly'=>'readonly',
                    ),
                ));?>
                <?php echo $form->error($model, 'on_sale_start'); ?>
            </div>
        </div>
        <div class="control-group">
            <?php echo $form->labelEx($model, 'on_sale_end', array('class' => 'control-label',)); ?>
            <div class="controls">
                <!--                --><?php //echo $form->textField($model, 'on_sale_end', array('readonly' => true,'class'=>'date-picker')) ?>
                <?php
                $timestamp = strtotime($model->on_sale_end);
                if ($timestamp !== false)
                    $model->on_sale_end = Yii::app()->getDateFormatter()->format($pattern, $timestamp);
                else
                    $model->on_sale_end = '';
                $datePicker = $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'id' => $idEnd,
                    'model' => $model,
                    'attribute' => 'on_sale_end',
                    // additional javascript options for the date picker plugin
                    'options' => array(
                        'dateFormat' => 'dd/mm/yy',
                        'beforeShow' => 'js:function(input, inst) {
    var minDate = $("#' . $idStart . '").val();
    if (minDate != "")
        minDate = $.datepicker.parseDate(\'dd/mm/yy\', minDate);
    if (!minDate)
        minDate = new Date();
    $(inst.input).datepicker("option", "minDate", minDate);
}'
                    ),
                    'htmlOptions' => array(
                        'class' => 'date-picker on_sale_end date-input',
                        'readonly'=>'readonly',
                    ),
                ));
                app()->clientScript->registerCssFile($datePicker->themeUrl . '/' . $datePicker->theme . '/' . $datePicker->cssFile);
                ?>
                <?php echo $form->error($model, 'on_sale_end');?>
            </div>
        </div>
    </div>
    <div class="control-group buttons">
        <div class="controls">
            <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class' => 'btn btn-primary')); ?>
        </div>
    </div>

    <?php $this->endWidget(); ?>
    <?php app()->clientScript->registerScript('on-sale', '
$("#product-form #' . CHtml::activeId($model, 'on_sale') . '").unbind("change");
$("#product-form #' . CHtml::activeId($model, 'on_sale') . '").bind("change",function(e){
    if($(this).is(":checked")){
        $(".on_sale-input").removeClass("hide");
    }else{
        $(".on_sale-input").addClass("hide");
    }
});
if ($("#product-form #' . CHtml::activeId($model, 'on_sale') . '").is(":checked"))
{
    $(".on_sale-input").removeClass("hide");
}
', CClientScript::POS_READY) ?>
</div><!-- form -->